package com.gitee.feizns.quickstart.ding.talk.api.top.api.smart.work.hrm.employee;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiSmartworkHrmEmployeeV2UpdateRequest;
import com.dingtalk.api.response.OapiSmartworkHrmEmployeeFieldGrouplistResponse;
import com.dingtalk.api.response.OapiSmartworkHrmEmployeeV2UpdateResponse;
import com.gitee.feizns.quickstart.ding.talk.utils.Utils;
import com.taobao.api.ApiException;

import java.util.List;

/**
 * 更新员工花名册信息（/topapi/smartwork/hrm/employee/v2/update）
 * 接口路径：<a href="https://open.dingtalk.com/document/orgapp/intelligent-personnel-update-employee-file-information">更新员工花名册信息（/topapi/smartwork/hrm/employee/v2/update）</a>
 * @link <a href="https://open.dingtalk.com/document/orgapp/intelligent-personnel-update-employee-file-information">服务端API 智能人事 花名册 更新员工花名册信息</a>
 * @author feizns
 * @since 2024/7/28
 */
public class V2Update {

    /**
     * 更新员工花名册信息（/topapi/smartwork/hrm/employee/v2/update）
     * @param accessToken 访问令牌
     * @param req {@link OapiSmartworkHrmEmployeeV2UpdateRequest}
     * @return {@link List }<{@link OapiSmartworkHrmEmployeeFieldGrouplistResponse.GroupMetaInfo }>
     * @throws ApiException API 异常
     */
    public static Boolean execute(String accessToken, OapiSmartworkHrmEmployeeV2UpdateRequest req) throws ApiException {
        DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/smartwork/hrm/employee/v2/update");
        OapiSmartworkHrmEmployeeV2UpdateResponse rsp = client.execute(req, accessToken);
        return Utils.ifErrorThrow(rsp).getResult();
    }

    /**
     * 请求
     * @param agentId 代理编号
     * @param param 参数
     * @return {@link OapiSmartworkHrmEmployeeV2UpdateRequest }
     */
    public static OapiSmartworkHrmEmployeeV2UpdateRequest request(Long agentId, OapiSmartworkHrmEmployeeV2UpdateRequest.EmpUpdateByCustomParam param) {
        OapiSmartworkHrmEmployeeV2UpdateRequest request = new OapiSmartworkHrmEmployeeV2UpdateRequest();
        request.setAgentid(agentId);
        request.setParam(param);
        return request;
    }

}
